<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- 请通过遍历的方式将以下数组中的0删除 -->
  <!-- let num = [1,2,0,3,0,4,0,0,0,5,6,7,8,9] -->
  <script>
    let num = [1, 2, 0, 3, 0, 4, 0, 0, 0, 5, 6, 7, 8, 9];

    // 使用for循环遍历数组
    for (let i = 0; i < num.length; i++) {
      if (num[i] === 0) {
        // 使用splice方法删除元素
        num.splice(i, 1);
        // 数组长度变化，需要回退索引
        i--;
      }
    }

    console.log(num); // [1, 2, 3, 4, 5, 6, 7, 8, 9]

  </script>


</body>

</html>